/*
 * Insets.java  0.4.0 / Oct 24, 2010
 *
 * Copyright (c) 2010 - 2011, cute4j.com and contributors.
 *
 * This software is licensed under the LGPL version 2.1 license.
 * A copy of this license is included in the file LICENSE-LGPL.txt.
 */
package com.cute4j.swing.graphics;

/**
 * Insets.
 *
 * @author Slobodan Vrkacevic
 * @version 0.4.0
 */
public class Insets {

// Public Static Fields. -------------------------------------------------------

  /**
   * Insets(0, 0, 0, 0) object.
   */
  public static final Insets ZERO_INSEST = new Insets();

// Private Fields. -------------------------------------------------------------

  private final int top;
  private final int left;
  private final int bottom;
  private final int right;
  private int hashCode; // NOPMD

// Public Constructors. --------------------------------------------------------

  /**
   * Constructs new Insets object.
   */
  public Insets() {
    top = 0;
    left = 0;
    bottom = 0;
    right = 0;
  }

  /**
   * Constructs new Insets object.
   *
   * @param top the inset from the top
   * @param left the inset from the left
   * @param bottom the inset from the bottom
   * @param right the inset from the right
   */
  public Insets(int top, int left, int bottom, int right) {
    this.top = top;
    this.left = left;
    this.bottom = bottom;
    this.right = right;
  }

// Public Methods. -------------------------------------------------------------

  /**
   * Returns top inset.
   *
   * @return top inset
   */
  public int getTop() {
    return top;
  }

  /**
   * Returns left inset.
   *
   * @return left inset
   */
  public int getLeft() {
    return left;
  }

  /**
   * Returns bottom inset.
   *
   * @return bottom inset
   */
  public int getBottom() {
    return bottom;
  }

  /**
   * Returns right inset.
   *
   * @return right inset
   */
  public int getRight() {
    return right;
  }

// Overridden Methods. ---------------------------------------------------------

  /**
   * {@inheritDoc}
   */
  public boolean equals(Object obj) {
    if (obj == this) {
      return true;
    }
    if ((obj != null) && (obj.getClass() == getClass())) {
      Insets ins = (Insets)obj;
      return ((ins.getTop() == getTop()) && (ins.getLeft() == getLeft()) &&
              (ins.getBottom() == getBottom()) &&
              (ins.getRight() == getRight()));
    }
    return false;
  }

  /**
   * {@inheritDoc}
   */
  public int hashCode() {
    if (hashCode == 0) {
      int hashCode = 223;
      hashCode = 67 * hashCode + getTop();
      hashCode = 67 * hashCode + getLeft();
      hashCode = 67 * hashCode + getBottom();
      hashCode = 67 * hashCode + getRight();
      this.hashCode = hashCode;
    }
    return hashCode;
  }

  /**
   * {@inheritDoc}
   */
  public String toString() {
    return getClass().getName() + "[top="  + getTop() + ",left=" + getLeft() +
           ",bottom=" + getBottom() + ",right=" + getRight() + "]";
  }

}
